﻿using AfterlifeLib;
using AfterlifeLib.GameScreens;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using AfterlifeLib.Input;

namespace Afterlife.Screens
{
    public class GamePlayScreen : GameScreen
    {
        ContentManager content;

        AfterlifeWorld world;

        public GamePlayScreen()
            : base()
        {
            
        }

        public override void LoadContent()
        {
            if(content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            world = new AfterlifeWorld(content, ScreenManager.GraphicsDevice, ScreenManager.SpriteBatch);
            world.Initialize();
            world.LoadContent();
        }

        public override void UnloadContent()
        {
            world.UnloadContent();
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (IsActive)
            {
                world.Update(gameTime);
            }
        }

        public override void HandleInput()
        {
            if (InputState.IsKeyFirstDown(Keys.Escape))
            {
                ScreenManager.AddScreen(new PauseMenuScreen());
            }
        }

        public override void Draw(GameTime gameTime)
        {
            world.Draw(gameTime);
        }
    }
}
